package com.example.blog.mapper;

import com.example.blog.model.BlogInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    //增加博客
    @Insert("INSERT INTO blog(title, content, user_id) values (#{BlogInfo.title},#{BlogInfo.content},#{BlogInfo.userId})")
    Integer insertBlogInfo(@Param("BlogInfo") BlogInfo blogInfo);
    //删除

    @Update("update java_blog_spring.blog set delete_flag=1 where id=#{id}")
    Integer deleteBlogInfoById(Integer id);
    //修改
    Integer updateInfo(BlogInfo blogInfo);

    //查询(自己可以查到自己所有的,或者通过blogId进行指定查询)
    @Select("select * from java_blog_spring.blog where id=#{id}")
    BlogInfo selectBlogInfo(@Param("id") Integer id);

    @Select("select id, title, content, user_id,update_time from java_blog_spring.blog where delete_flag=0  ORDER BY update_time DESC")
    List<BlogInfo> selectBlogInfoAll();

}
